Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to upstream and upstreammembers #1233

Merged
merged 1 commit into from
Oct 20, 2018

Conversation

SaschaDoering
Copy link
Contributor

@SaschaDoering SaschaDoering commented Jul 16, 2018

Pull Request (PR) description

Add parameters to upstream and upstreammembers

Add parameters to nginx::resource::upstream and
nginx::resource::upstream::member which allows more configuration on
upstreams as before. The only thing that we broke is that the
members of an upstream must now be passed as a hash rather than an
array. This also makes the sorting of keepalive to the end no
longer necessary because there is now a parameter for it. And
values for a nginx::resource::upstream::member can now be set as
default for all members of an upstream or individually for each
member inside the members hash. Of course, the explicit
specification overrides the defaults. In general the changes have
made more parameters available to nginx::resource::upstream and
nginx::resource::upstream::member. In addition, one of the two
templates for nginx::resource::upstream::member was disposed since
it is no longer needed.

This Pull Request (PR) fixes the following issues

Fixes GH-1222

@ghost ghost force-pushed the add_upstream_parameters branch from cf49d4c to 91a8a7b Compare July 16, 2018 15:00
@juniorsysadmin juniorsysadmin added backwards-incompatible needs-feedback Further information is requested labels Aug 5, 2018
@SaschaDoering
Copy link
Contributor Author

@juniorsysadmin Which kind of feedback do you need from me?

@juniorsysadmin
Copy link
Member

@SaschaDoering Nothing required from you just yet, but given this is a breaking change it would good to get some approval on the design from other users before merging.

@SaschaDoering
Copy link
Contributor Author

Thanks for the feedback, I thought something was missing from my side :)

@baurmatt
Copy link
Contributor

LGTM! :)

@bastelfreak
Copy link
Member

Is the only breaking change the new datatype for $members? Then it should be possible to implement this without backwards incompatible changes?

@SaschaDoering
Copy link
Contributor Author

Yes, this should be the only breaking change. In addition, it is possible to set different values for members of the upstream which is necessary for things like weight. I also don't see a reason for adding extra code for the old method given the README.md states Please note: This module is undergoing some structural maintenance. You may experience breaking changes between minor versions. Especially since the changes to the configuration will be very minimal. On the other hand, the changes in the code would not be so minimal. Would it help to expand the README.md with a migration example?

@bastelfreak
Copy link
Member

sure this is mentioned in the readme and we still didn't do a 1.0.0 release, but still backwards compatibility is always nice. Can you add backwards support or update the READMe.md?

Copy link
Member

@bastelfreak bastelfreak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some inline comments, please have a look. Can you add some acceptance tests so we now this works?

Enum['http', 'stream'] $upstream_context = 'http',
Enum['present', 'absent'] $ensure = 'present',
Enum['http', 'stream'] $context = 'http',
Optional[Hash] $members = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this default to an empty hash instead of optional? We have some guidelines for datatypes at https://voxpupuli.org/docs/#reviewing-a-module-pr

  • Are there new params with datatype Hash or Array? If possible, they should default to empty Hash/Array instead of undef. You can also enforce the datastructure like Array[String]

and:

  • If you can supply one or multiple values for an attribute it’s common practice to enforce the datatype for one value and an array of that datatype. An example for string is Variant[String[1],Array[String[1]]]. This can be used in the Puppet code as [$var].flatten()

can you also define the datatypes within the hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll fix that.

Optional[String] $members_tag = undef,
Optional[Nginx::UpstreamMemberDefaults] $member_defaults = undef,
Optional[String] $hash = undef,
Optional[Boolean] $ip_hash = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check all parameters with the Boolean dataype. If it makes sense, remove the Optional and let them default to True or False

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, again, I'll fix that, too.

@upstream_cfg_append['keepalive'] = @upstream_cfg_append.delete('keepalive')
-%>
<%- @upstream_cfg_append.each do |key,value| -%>
<% if @hash -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you interested in turning this into an epp template? From our docs:

  • Is a new template added? The preferred language is epp, not erb

it isn't required to turn this into an epp template, but it would be nice to have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I convert upstream_member.erb I will convert this too. It makes no sense to use different templatetypes for one file I think.

@@ -1 +1,12 @@
server <%= @server %>:<%= @port %> fail_timeout=<%= @upstream_fail_timeout %><% if @upstream_max_fails -%> max_fails=<%=@upstream_max_fails %><% end %>;
server <%= @_server %><% if @params_prepend -%> <%= @params_prepend %><% end -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please convert this into an epp template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll convert the template.

@bastelfreak bastelfreak added enhancement New feature or request needs-tests needs-work not ready to merge just yet and removed needs-feedback Further information is requested labels Aug 29, 2018
@ghost ghost force-pushed the add_upstream_parameters branch 5 times, most recently from 41ccfe2 to bf8febd Compare September 5, 2018 14:07
@SaschaDoering
Copy link
Contributor Author

I pushed a new version a few moments ago which should fix the issues you commented. Please let me know if I missed something, thanks.

Optional[Nginx::UpstreamSticky] $sticky = undef,
Optional[Nginx::UpstreamZone] $zone = undef,
Hash $cfg_append = {},
Hash $cfg_prepend = {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you enforce the datatypes within the hash please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a datatype for this.

Boolean $ntlm = false,
Optional[Integer] $queue_max = undef,
Optional[Nginx::Time] $queue_timeout = undef,
Optional[String] $random = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For strings, please always use String[1], it will enforce a minimal string length of 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed.

@@ -0,0 +1,113 @@
require 'spec_helper_acceptance'

describe 'nginx::resource::upstream define:' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acceptance tests \o/

@ghost ghost force-pushed the add_upstream_parameters branch 3 times, most recently from 9d4b426 to 4272747 Compare September 6, 2018 13:36
@ghost ghost force-pushed the add_upstream_parameters branch from 4272747 to aa529c7 Compare September 6, 2018 13:44
Add parameters to nginx::resource::upstream and
nginx::resource::upstream::member which allows more configuration on
upstreams as before. The only thing that we broke is that the
members of an upstream must now be passed as a hash rather than an
array. This also makes the sorting of keepalive to the end no
longer necessary because there is now a parameter for it. And
values for a nginx::resource::upstream::member can now be set as
default for all members of an upstream or individually for each
member inside the members hash. Of course, the explicit
specification overrides the defaults. In general the changes have
made more parameters available to nginx::resource::upstream and
nginx::resource::upstream::member. In addition, one of the two
templates for nginx::resource::upstream::member was disposed since
it is no longer needed.

Fixes voxpupuliGH-1222
@ghost ghost force-pushed the add_upstream_parameters branch from aa529c7 to f0bf83a Compare September 6, 2018 13:58
@SaschaDoering
Copy link
Contributor Author

I pushed an updated version which fix the datatype issues. So it's your turn again ;) Thanks.

@bastelfreak
Copy link
Member

looks good to me, thanks to the massive PR! I will keep this open so we can get another review from somebody else.

@SaschaDoering
Copy link
Contributor Author

Ok, thanks for the review.

Copy link
Member

@dhollinger dhollinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple questions surrounding the changes to the $members parameter, specifically around how the datatype parses that parameter and if there's another way to do it.

members => {
'localhost:3000':
server => 'localhost'
port => 3000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance this can be a little confusing. My first question would be "Why not parse the localhost:3000 into server and port?"

Could we potentially make it an array of hashes so that it looks more like:

nginx::resource::upstream { 'puppet_rack_app':
  members => [
    {
      server => 'localhost',
      port    => 3000,
    },
    {
      server => 'localhost',
      port    => 3001,
    },
    {
      server => 'localhost',
      port    => 3002,
    },
  ]

Does that work or does the parameter rely on each member to have a unique name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly cause Unix sockets are accepted too. We would first have to see if it is a valid Unix socket and only if not split at the colon. After that we need to check the parts if they are valid. We almost have to implement the used datatype in code. And at the end we have the problem to name the resources for the defined type which is necessary for exporting upstream members. That's why we need a unique name here.
Should I change the README.md file and use keys that do not consist of server and port? Maybe it's a good idea to use the keys as default for the comment.

Enum['http', 'stream'] $upstream_context = 'http',
Enum['present', 'absent'] $ensure = 'present',
Enum['http', 'stream'] $context = 'http',
Nginx::UpstreamMembers $members = {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

@SaschaDoering
Copy link
Contributor Author

Is there anything left or any open points to discuss?

@bastelfreak
Copy link
Member

Hey @voxpupuli/collaborators, could I get your feedback here?

@baurmatt
Copy link
Contributor

Can we please get this merged or an update what changes should be made?

order => '90',
content => template('nginx/upstream/upstream_footer.erb'),
content => epp('nginx/upstream/upstream_footer.epp', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is for no parameters for epp(), where possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly prefer them, because that allows scoped variables with proper datatypes.

@juniorsysadmin juniorsysadmin removed the needs-work not ready to merge just yet label Oct 20, 2018
@juniorsysadmin juniorsysadmin merged commit 74703e3 into voxpupuli:master Oct 20, 2018
alexjfisher added a commit to alexjfisher/puppet-nginx that referenced this pull request Feb 26, 2019
voxpupuli#1233 was a breaking
change that amongst other things, renamed this parameter.

Fixes voxpupuli#1316
cegeka-jenkins pushed a commit to cegeka/puppet-nginx that referenced this pull request Sep 13, 2019
Add parameters to upstream and upstreammembers
cegeka-jenkins pushed a commit to cegeka/puppet-nginx that referenced this pull request Sep 13, 2019
voxpupuli#1233 was a breaking
change that amongst other things, renamed this parameter.

Fixes voxpupuli#1316
Rubueno pushed a commit to Rubueno/puppet-nginx that referenced this pull request Oct 19, 2020
Add parameters to upstream and upstreammembers
Rubueno pushed a commit to Rubueno/puppet-nginx that referenced this pull request Oct 19, 2020
voxpupuli#1233 was a breaking
change that amongst other things, renamed this parameter.

Fixes voxpupuli#1316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nginx::resource::upstream make consistent use of nginx::resource::upstream::member
6 participants